package com.retail.xiaocui.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.retail.xiaocui.common.domain.req.OrderReq;
import com.retail.xiaocui.server.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.xiaocui.common.domain.WarehouseSku;
import com.retail.xiaocui.server.service.WarehouseSkuService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * 商品库存Controller
 *
 * @author retail
 * @date 2024-03-10
 */
@RestController
@RequestMapping("/sku")
public class WarehouseSkuController extends BaseController
{
    @Autowired
    private WarehouseSkuService warehouseSkuService;


    @Autowired
    private WarehouseService warehouseService;

    /**
     * 查询商品库存列表
     */
    @RequiresPermissions("xiaocui:sku:list")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseSku warehouseSku)
    {
        startPage();
        List<WarehouseSku> list = warehouseSkuService.selectWarehouseSkuList(warehouseSku);
        return getDataTable(list);
    }

    /**
     * 导出商品库存列表
     */
    @RequiresPermissions("xiaocui:sku:export")
    @Log(title = "商品库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseSku warehouseSku)
    {
        List<WarehouseSku> list = warehouseSkuService.selectWarehouseSkuList(warehouseSku);
        ExcelUtil<WarehouseSku> util = new ExcelUtil<WarehouseSku>(WarehouseSku.class);
        util.exportExcel(response, list, "商品库存数据");
    }

    /**
     * 获取商品库存详细信息
     */
    @RequiresPermissions("xiaocui:sku:query")
    @GetMapping(value = "/{warehouseSkuId}")
    public Result getInfo(@PathVariable("warehouseSkuId") Integer warehouseSkuId)
    {
        return success(warehouseSkuService.selectWarehouseSkuByWarehouseSkuId(warehouseSkuId));
    }

    /**
     * 新增商品库存
     */
    @RequiresPermissions("xiaocui:sku:add")
    @Log(title = "商品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody WarehouseSku warehouseSku)
    {
        return toAjax(warehouseSkuService.insertWarehouseSku(warehouseSku));
    }

    /**
     * 修改商品库存
     */
    @RequiresPermissions("xiaocui:sku:edit")
    @Log(title = "商品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody WarehouseSku warehouseSku)
    {
        return toAjax(warehouseSkuService.updateWarehouseSku(warehouseSku));
    }

    /**
     * 删除商品库存
     */
    @RequiresPermissions("xiaocui:sku:remove")
    @Log(title = "商品库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseSkuIds}")
    public Result remove(@PathVariable Integer[] warehouseSkuIds)
    {
        return toAjax(warehouseSkuService.deleteWarehouseSkuByWarehouseSkuIds(warehouseSkuIds));
    }

    /**
     * 查询仓库所有信息
     * @return
     */
    @GetMapping("/warehouseList")
    public Result warehouseList(){
        return warehouseService.warehouseList();
    }


    /**
     * 下单减库存
     * @param orderReq
     * @return
     */
    @PostMapping("/orderRequest")
    public Result orderRequest(@RequestBody OrderReq orderReq){
        return warehouseSkuService.orderRequest(orderReq);
    }




}
